package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.BookOrder;
import com.xuetang9.t9.hotel.services.IBookOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName: MyHotelProject
 * @Package: com.xuetang9.t9.hotel.controller
 * @ClassName: BookOrderController
 * @Author: ChinaHp
 * @Description: 预定订单控制层
 * @Date: 2020/2/24 17:26
 * @Version: 1.0
 */
@Controller
@RequestMapping("bookOrder")
@ResponseBody
public class BookOrderController {
    @Autowired
    private IBookOrderService service;

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    private Map save(@RequestBody BookOrder bookOrder){
        Map map  = new HashMap();
        if(bookOrder == null ){
            map.put(400,"参数错误");
            return map;
        }
        if(!service.add(bookOrder)){
            map.put(500,"操作错误");
            return map;
        }
        map.put(200,"操作成功");
        return map;
    }

    @PostMapping("list")
    public List<BookOrder> queryAll(){
        System.out.println("所有");
        return service.query();
    }

    @PostMapping("del")
    public boolean del(@RequestParam("id")String id){
        System.out.println(id);
        if(service.remove(Integer.parseInt(id))){
            System.out.println("删除成功");
            return true;
        }
        return false;
    }

    @PostMapping("add")
    public boolean add(){
        return false;
    }

    @PostMapping("update")
    public boolean update(){
        return false;
    }

    @PostMapping("todayTheOrder")
    public List<BookOrder> todayTheOrder(){
        System.out.println("今日");
         return service.todayTheOrder();
    }

    @PostMapping("queryByState")
    public List<BookOrder> queryByState(@RequestParam("state")String state){
        System.out.println(state);
        return service.queryStateOrder(state);
    }

    /**
     * 根据预订订单id查询预订订单
     * @param id
     * @return
     */
    @RequestMapping(value = "/que/{id}")
    private Map save(@PathVariable("id") Integer id){
        Map map  = new HashMap();
        if(id == null ){
            map.put(400,"参数错误");
            return map;
        }
        BookOrder bookOrder = service.selectById(id);
        if(bookOrder == null){
            map.put(500,"操作错误");
            return map;
        }
        map.put(200,bookOrder);
        return map;
    }
}
